<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">
	</head>
	<body>

		<div class="layui-fluid">
            <div class="layui-row layui-col-space15" id="ledgerDataView">
            </div>
            <script type="text/html" id="ledgerDataTPL">
                <div class="layui-col-md6">
                    <div class="layui-card">
                        <div class="layui-card-header">A仓统计</div>
                        <div class="layui-card-body">
                            <div class="layui-carousel layadmin-carousel layadmin-backlog">
                                <div>
                                    <ul class="layui-row layui-col-space10">
                                        <li class="layui-col-xs6 caaountYu" data-accountname="A仓金额" data-accountid="{{d.account_201.accountid}}">
                                            <a href="javascript:;" class="layadmin-backlog-body">
                                                <h3>A仓金额</h3>
                                                <p><cite class="today_trans_count">{{ d.account_201 ? '￥' + d.account_201.money : '-' }}</cite></p>
                                            </a>
                                        </li>
                                        <li class="layui-col-xs6 caaountYu" data-accountname="A仓已释放" data-accountid="101">
                                            <a href="javascript:;" class="layadmin-backlog-body">
                                                <h3>A仓已释放</h3>
                                                <p><cite class="today_trans_sum">{{ d.shop_account_ledger.data.cash_out_a ? '￥' + d.shop_account_ledger.data.cash_out_a : '-' }}</cite></p>
                                            </a>
                                        </li>
                                        <li class="layui-col-xs6 caaountYu" data-accountname="A仓累计金额" data-accountid="{{d.account_201.accountid}}">
                                            <a href="javascript:;" class="layadmin-backlog-body">
                                                <h3>A仓累计金额</h3>
                                                <p><cite class="today_trans_count">{{ d.shop_account_ledger.data.cash_total_a ? '￥' + d.shop_account_ledger.data.cash_total_a : '-' }}</cite></p>
                                            </a>
                                        </li>
										<!--  -->
                                        <li class="layui-col-xs6 release" data-accountname="A仓释放比例">
                                            <a href="javascript:;" class="layadmin-backlog-body">
                                                <h3>A仓释放比例</h3>
                                                <p><cite class="today_trans_sum">{{ d.shop_account_ledger.data.cash_rate_a ? (d.shop_account_ledger.data.cash_rate_a * 100).toFixed(2) + '%' : '-' }}</cite></p>
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md3">
                    <div class="layui-card">
                        <div class="layui-card-header">B&C仓统计</div>
                        <div class="layui-card-body">
                            <div class="layui-carousel layadmin-carousel layadmin-backlog">
                                <div>
                                    <ul class="layui-row layui-col-space10">
                                        <li class="layui-col-xs12 caaountYu" data-accountname="B仓金额"  data-accountid="{{d.account_202.accountid}}">
                                            <a href="javascript:;" class="layadmin-backlog-body">
                                                <h3>B仓金额</h3>
                                                <p><cite class="yes_today_trans_count">{{ d.account_202 ? '￥' + d.account_202.money : '-' }}</cite></p>
                                            </a>
                                        </li>
                                        <li class="layui-col-xs12 caaountYu" data-accountname="C仓金额"  data-accountid="{{d.account_203.accountid}}">
                                            <a href="javascript:;" class="layadmin-backlog-body">
                                                <h3>C仓金额</h3>
                                                <p><cite class="yes_today_trans_sum">{{ d.account_203 ? '￥' + d.account_203.money : '-' }}</cite></p>
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md3">
                    <div class="layui-card">
                        <div class="layui-card-header">其他仓统计</div>
                        <div class="layui-card-body">
                            <div class="layui-carousel layadmin-carousel layadmin-backlog">
                                <div>
                                    <ul class="layui-row layui-col-space10">
                                        <li class="layui-col-xs12 caaountYu" data-accountname="商家金额" data-accountid="{{d.account_107.accountid}}">
                                            <a href="javascript:;" class="layadmin-backlog-body">
                                                <h3>商家金额</h3>
                                                <p><cite class="yes_today_trans_count">{{ '￥' + d.account_107.money }}</cite></p>
                                            </a>
                                        </li>
                                        <li class="layui-col-xs12 caaountYu" data-accountname="会员余额" data-accountid="{{d.account_100.accountid}}">
                                            <a href="javascript:;" class="layadmin-backlog-body">
                                                <h3>会员余额</h3>
                                                <p><cite class="yes_today_trans_sum">{{ '￥' + d.account_100.money }}</cite></p>
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </script>
			<div class="layui-row layui-col-space15">
                <!-- 表格数据 -->
				<div class="layui-col-md12">
					<div class="layui-card">
                        <div class="layui-card-header">日结记录</div>
                        <div class="layui-card-body">
                            <!-- 搜索 -->
                            <form class="layui-form search" id="form" onsubmit="return false" action="##">
                                <div class="layui-inline search_inline">
                                    <label class="layui-form-label">记账时间段：</label>
                                    <div class="layui-input-inline" style="width: 300px;">
                                        <input class="layui-input" id="choosetime" placeholder="时间段" autocomplete="off"
                                            value="">
                                        <input class="layui-input" type="text" id="starttime" value="" name="starttime"
                                            placeholder="" autocomplete="off" style="display: none;">
                                        <input class="layui-input" type="text" id="endtime" value="" name="endtime"
                                            placeholder="" autocomplete="off" style="display: none;">
                                    </div>
                                </div>

                                <button class="layui-btn search_inline" lay-submit="" lay-filter="search" data-type="reload">搜索</button>
                                <button class="layui-btn layui-btn-primary search_inline" type="reset">重置</button>
                            </form>
                            <!-- 搜索 -->
                            <table id="table-main" lay-filter="table-main-operate"></table>
                        </div>
					</div>
				</div>
			</div>
		</div> 
		<script src="../../../layuiadmin/layui/layui.js?t=1"></script>
		<script src="../../../js/common.js"></script>
		<script>
			layui.config({
				base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'table', 'form', 'element', 'laytpl', 'laydate'], function() {
				var table = layui.table,
					$ = layui.$,
					form = layui.form,
					laytpl = layui.laytpl,
                    laydate = layui.laydate,
					element = layui.element,
					admin = layui.admin;
                    laydate.render({
                        elem: '#choosetime',
                        type: 'date',
                        range: true,
                        value: '',  // 将默认日期设为空字符串
                        done: function (value, date) {
                            console.log(value);
                            $('input[name=starttime]').val(value.split(' - ')[0]);
                            $('input[name=endtime]').val(value.split(' - ')[1]);
                        }
                    });

                initdata();

				function initdata() {
					$.get(server.sys_account_ledger_query, {}, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
                                
								var data = res;
                                $.each(data.usable_amount.data, function(index, item) {
                                    console.log(item)
                                    var key = 'account_' + item.accountid
                                    data[key] = {
                                        accountid: item.accountid,
                                        money: item.money
                                    }
                                })
                                console.log(data)
								var ledgerDataView = document.getElementById('ledgerDataView');
								laytpl(ledgerDataTPL.innerHTML).render(data, function(html) {
									ledgerDataView.innerHTML = html;
								});
								
								$(`.caaountYu`).on('click', function() {
									console.log($(this).data('accountname'));
									if($(this).data('accountname')=='A仓已释放'){
										layer.open({
											type: 2,
											title: $(this).data('accountname'),
											shadeClose: false,
											shade: 0.5,
											area: ['90%', '90%'],
											content: 'model/account_list.html?id=' + $(this).data('accountid')+'&type=动态释放'+'&name='+$(this).data('accountname'),
											end: function() {}
										});
									}else{
										layer.open({
											type: 2,
											title: $(this).data('accountname'),
											shadeClose: false,
											shade: 0.5,
											area: ['90%', '90%'],
											content: 'model/account_list.html?id=' + $(this).data('accountid')+'&name='+$(this).data('accountname'),
											end: function() {}
										});
									}
									
								})
								
								// 释放比例
								$(`.release`).on('click', function() {
									console.log($(this).data('accountname'));
									layer.open({
										type: 2,
										title: $(this).data('accountname'),
										shadeClose: false,
										shade: 0.5,
										area: ['90%', '90%'],
										content: 'model/release_ratio.html',
										end: function() {}
									});
									
								})
								
								
							} else {
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
                var _data = {}
                queryMainTableData()
                function queryMainTableData() {
                    //今日待发货订单
                    table.render({
                        elem: '#table-main',
                        page: true,
                        where: _data,
                        limit: limit,
                        limits: limits,
                        height: 'full-410',
                        url: server.sys_account_daily_list,
                        cols: [
                            [
                                // { field: 'shopid', width: 120, title: '店铺编号', fixed: 'left' },
                                { 
                                    field: 'accountday', width: 200, title: '日期', fixed: 'left',
                                    templet: function(d) {
                                        return '<a class="text_blue_color" href="javascript:;" lay-event="accountday">' + d.accountday + '</a>'
                                    }
                                },
                                // { field: 'accountid', width: 120, title: '帐户编号' },
                                { field: 'accountname', width: 220, title: '帐户名称' },
                                { field: 'cash_amount', width: 300, title: '日结金额' },

                                { field: 'cash_a', width: 300, title: 'A仓金额' },
                                { field: 'cash_out_a', width: 300, title: 'A仓已释放' },
                                // { field: 'cash_total_a', width: 120, title: 'A仓累计金额' },
                                { 
									field: 'cash_rate_a', width: 300, title: 'A仓释放比例',
									templet: function(d) {
										 return d.cash_rate_a>0?'<div>'+((d.cash_rate_a)*10000).toFixed(2)+'/万'+'</div>':'0'
									}
								 },

                                // { field: 'cash_b', width: 120, title: '仓位B金额' },
                                // { field: 'cash_out_b', width: 120, title: '仓位B已释放' },
                                // { field: 'cash_total_b', width: 120, title: '仓位B累计金额' },
                                // { field: 'cash_rate_b', width: 120, title: '仓位B释放比率' },

                                // { field: 'cash_c', width: 120, title: '仓位C金额' },
                                // { field: 'cash_out_c', width: 120, title: '仓位C已释放' },
                                // { field: 'cash_total_c', width: 120, title: '仓位C累计金额' },
                                // { field: 'cash_rate_c', width: 120, title: '仓位C释放比率' },

                                // { field: 'memo', width: 120, title: '备注' },
                                // { field: 'addtime', width: 120, title: '创建时间' },
                                
                            ]
                        ],
                        parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
                            return {
                                "code": res.code, //解析接口状态
                                "msg": res.msg, //解析提示文本
                                "count": res.shop_account_daily.pager.total, //解析数据长度
                                "data": res.shop_account_daily.data //解析数据列表
                            };
                        }
                    });
                }

                //监听表格点击
                table.on('tool(table-main-operate)', function(obj) {
                    var data = obj.data;
                    console.log(obj);
                    if (obj.event === 'accountday') {
                        layer.open({
                            type: 2,
                            title: '记账日[' + data.accountday + ']明细',
                            shade: 0.5,
                            maxmin: true, //开启最大化最小化按钮
                            area: ['90%', '90%'],
                            content: '../model/account_ledger_detail.html?shopid=' + data.skuid + "&accountday=" + data.accountday,
                            end: function() {}
                        });
                    }
                })

                //监听搜索
                form.on('submit(search)', function(data) {
                    Object.assign(_data, data.field)
                    console.log(_data);
                    queryMainTableData();
                    return false;
                });

                $("button[type=reset]").on("click", function() {
                    _data = {}
                    queryMainTableData();
                    document.getElementById("form").reset();
                });
				
			});
		</script>
	</body>
</html>
